<h4 class="h4"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>&nbsp;添加课程</h4>
<form class="layui-form" action="comm/addcurriculum.php" name="editForm" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px;">课程名称</label>
        <div class="layui-input-block">
            <input type="text" name="cname" required lay-verify="cname" placeholder="课程名称" autocomplete="off"
                class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label" style="width:100px;">课程学分</label>
        <div class="layui-input-block">
            <input type="number" name="credit" placeholder="请输入课程学分" autocomplete="off" class="layui-input" lay-verify="credit">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label" style="width:100px;">输入介绍</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入内容" class="layui-textarea" name="info" lay-verify="info"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<style>
    .file {
        display: flex;
        justify-content: center;
    }
</style>
<script>
    //Demo
    layui.use('form', function () {
        var form = layui.form;

        form.verify({
            username: function (value, item) { //value：表单的值、item：表单的DOM对象
                if(!value){
                    return "课程名称为空"
                }
            },
            credit:(value, item)=>{
                if(!value){
                    return "课程学分不能为空"
                }
                if (parseInt(value)<0||parseInt(value)>10){
                    return "学分应该是0~10"
                }
            },
            info:(value, item)=>{
                if(!value){
                    return "课程介绍不能为空"
                }
                if(value.length<5||value.length>200){
                    return "课程介绍字数在5~200"
                }
            }
        });
    });
    $(".newspic").click(function () {
        $(this).next('input').click();
    });


</script>